package com.azt.front.action.activity;

import com.azt.api.pojo.FinanceApplyReq;
import com.azt.api.pojo.SignApplyReq;
import com.azt.api.pojo.User;
import com.azt.api.service.FinanceApplyService;
import com.azt.front.model.ApiResponse;
import com.azt.front.utils.ContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * 金融服务
 * Created by LiQZ on 2017/3/15.
 */
@Controller
public class FinanceApplyAction {

    public static final Logger logger = LoggerFactory.getLogger(FinanceApplyAction.class);

    @Autowired
    private FinanceApplyService financeApplyService;

    @RequestMapping("finance")
    public String finance(Model model) {
    	model.addAttribute("link", "index");
        return "activity/finance";
    }

    @ResponseBody
    @RequestMapping(value = "finance/apply", method = RequestMethod.POST, produces="application/json;charset=UTF-8")
    public ApiResponse apply(@Valid FinanceApplyReq req) {
        // 获取当前用户(可能没有)
        User user = ContextUtil.getUser();
        if (user != null) {
            req.setUserId(user.getId());
        }
        logger.debug("input finance apply params is {} user {}", req, user);
        financeApplyService.save(req);
        return ApiResponse.SUCCESS;
    }

}
